'use strict';
angular.module('app.user')
.service('fileUpload', ['$http', function ($http) {
    this.uploadFileToUrl = function (file, uploadUrl) {
        console.log(file);
        var fd = new FormData();
        fd.append('userfile', file);
     
        $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: { 'Content-Type': undefined }
        })
        .success(function (response) {
            console.log("success------------------");
            console.log(response);
        })
        .error(function () {
            console.log("error------------------");
        });
    }
}]);

'use strict';
angular.module('app.user')
.directive('ngFileSelect', ['$parse', '$timeout', function ($parse, $timeout) {
    return function (scope, elem, attr) {
        var fn = $parse(attr['ngFileSelect']);
        elem.bind('change', function (evt) {
            var files = [], fileList, i;
            fileList = evt.target.files;
            if (fileList != null) {
                for (i = 0; i < fileList.length; i++) {
                    files.push(fileList.item(i));
                }
            }
            $timeout(function () {
                fn(scope, {
                    $files: files,
                    $event: evt
                });
            });
        });
    };
}])


'use strict';
angular.module('app.user').factory('userHttpS', ['Restangular', function(Restangular) {
    return {
        getAll:function(id){
            return Restangular.one('permission/getaction/', id).get();
        },
        getList:function(tableName){
         
            return Restangular.one('user', 'get_tableInf').getList(tableName);
        
        },
        getAlls:function(functionName){
        
            return Restangular.one('user',functionName).getList();
        },
        postAll:function(functionName,data){
           return Restangular.one('user').post(functionName,data);
        },
        postAllAdmin:function(functionName,data){
            return Restangular.one('admin').post(functionName,data);
        },
       	post:function(functionName,data){
            return Restangular.one('user').post(functionName, data);
        },
        get:function(functionName){
            return Restangular.one('user',functionName).get();
        },
        getUserInfo: function () {
            return Restangular.one('user', 'getUserInfo').get();
        },
        getrealName:function () {
            return Restangular.one('user', 'getrealName').get();
        },
        getJoinCompany: function () {
//            return Restangular.one('user', 'getUserInfo').get();
            return Restangular.one('PersonalCenter','user_join_comp').get();
        }
    };         
   }]);
